package com.buleqr.controller;

import com.buleqr.dto.request.AddCouponCodeReq;
import com.buleqr.dto.request.CouponQuery;
import com.buleqr.pojo.AjaxResult;
import com.buleqr.pojo.CouponCode;
import com.buleqr.service.ICouponCodeService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 新闻
 *
 * @author buleqr
 */
@Slf4j
@RestController
@RequestMapping("/couponCode")
@AllArgsConstructor
public class CouponCodeController {
    private final ICouponCodeService couponService;



    /**
     * @return 结果
     */
    @PostMapping("/batchCreate")
    @PreAuthorize("hasAnyAuthority('admin')")
    public AjaxResult batchCreate(@Valid @RequestBody AddCouponCodeReq req) {
        return couponService.batchCreate(req);
    }

    /**
     * @param query 参数
     * @return 结果
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody CouponQuery query) {
        return AjaxResult.success(couponService.list(query));
    }
}
